package org.song.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.song.exception.result.AjaxResult;
import org.song.model.dto.GroupChatDto;
import org.song.model.vo.GroupChat;
import org.song.service.GroupChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 博客聊天组控制层
 */
@Api(tags = "博客聊天组控制层")
@Controller
@RequestMapping(value = "/groupChat")
public class GroupChatController {

    @Autowired( required = true )
    @Qualifier( value = "groupChatServiceImpl")
    private GroupChatService groupChatService;

    /**
     * 查询所有的博客聊天组
     * @param groupChatDto
     * @return
     */
    @ApiOperation(value = "查询所有的博客聊天组" , notes = "查询所有的博客聊天组")
    @ResponseBody
    @RequestMapping(value = "/listGroupChats" , method = RequestMethod.GET)
    public AjaxResult<List<GroupChat>> listGroupChats(@ApiParam(value = "groupChatDto实例接受查询参数") @NonNull GroupChatDto groupChatDto) {
        PageHelper.startPage(groupChatDto.getPage() , groupChatDto.getSize());
       return AjaxResult.success(groupChatService.listGroupChats(groupChatDto));
    }

    /**
     * 删除博客聊天组
     * @param groupChat
     * @return
     */
    @ApiOperation(value = "删除博客聊天组" , notes = "删除博客聊天组")
    @ResponseBody
    @RequestMapping(value = "/deleteGroupChat" , method = RequestMethod.DELETE)
    public AjaxResult<Integer> deleteGroupChat(@ApiParam(value = "接受需要删除的博客聊天组") @NonNull @RequestBody GroupChat groupChat) {
        return AjaxResult.success(groupChatService.deleteGroupChat(groupChat));
    }

    /**
     * 增加博客聊天组
     * @param groupChat
     * @return
     */
    @ApiOperation(value = "增加博客聊天组" , notes = "增加博客聊天组")
    @ResponseBody
    @RequestMapping(value = "/insertGroupChat" , method = RequestMethod.PUT)
    public AjaxResult<Integer> insertGroupChat(@ApiParam(value = "博客聊天组") @NonNull @RequestBody GroupChat groupChat) {
        return AjaxResult.success(groupChatService.insertGroupChat(groupChat));
    }

    /**
     * 更新博客聊天组
     * @param groupChat
     * @return
     */
    @ApiOperation(value = "更新博客聊天组" , notes = "更新博客聊天组")
    @ResponseBody
    @RequestMapping(value = "/updateGroupChat" , method = RequestMethod.POST)
    public AjaxResult<Integer> updateGroupChat(@ApiParam(value = "根据传入的聊天组信息进行博客聊天组更新") @NonNull @RequestBody GroupChat groupChat) {
        return AjaxResult.success(groupChatService.updateGroupChat(groupChat));
    }


}
